# -*- coding:utf-8 -*-
'''
输入一个链表，反转链表后，输出链表的所有元素。
'''
class ListNode:
    def __init__(self, x):
        self.val = x
        self.next = None

class Solution:
    # 返回ListNode
    def ReverseList(self, pHead):
        # write code here
        if pHead is None:
            return
        if pHead.next is None:
            return pHead
        else:
            newpHead = self.ReverseList(pHead.next) # 找到链表尾部
            pHead.next.next = pHead                 # 翻转链表
            pHead.next = None                       # 尾指针置空
            return newpHead

one = ListNode(1)
two = ListNode(2)
three = ListNode(3)
two.next = three
one.next = two
s = Solution()
a = s.ReverseList(one)
print(a)